package com.yunhai.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunhai.common.dto.GlobalException;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.utils.ObjectUtil;
import com.yunhai.common.utils.ReflectionCopy;
import com.yunhai.device.mapper.OrrOutcupEfficiencyDetailMapper;
import com.yunhai.device.service.OrrOutcupEfficiencyDetailService;
import com.yunhai.model.entity.orr.OrrOutcupEfficiencyDetailEntity;
import com.yunhai.model.vo.orr.OrrOutcupEfficiencyDetailQuery;
import com.yunhai.model.vo.orr.OrrOutcupEfficiencyDetailVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrrOutcupEfficiencyDetailServiceImpl implements OrrOutcupEfficiencyDetailService {

    @Resource
    private OrrOutcupEfficiencyDetailMapper orrOutcupEfficiencyDetailMapper;

    /**
     * 获取 OrrOutcupEfficiencyDetail 分页列表
     */
    @Transactional
    public IPage getOrrOutcupEfficiencyDetailPagination(PaginationVo paginationVo, OrrOutcupEfficiencyDetailQuery orrOutcupEfficiencyDetailQuery ) throws Exception {

        IPage page = new Page( paginationVo.getPageIndex(), paginationVo.getPageSize() );
        LambdaQueryWrapper<OrrOutcupEfficiencyDetailEntity> lqs = new LambdaQueryWrapper();
        orrOutcupEfficiencyDetailMapper.selectPage(page, lqs);

        List<OrrOutcupEfficiencyDetailEntity> record = page.getRecords();
        if( !ObjectUtil.isNotEmptyList(record)){
            return page;
        }
        return page;
    }


    /**
     * 获取 OrrOutcupEfficiencyDetail 所有数据
     *
     */
    @Transactional
    public List<OrrOutcupEfficiencyDetailEntity> getOrrOutcupEfficiencyDetailAllList( OrrOutcupEfficiencyDetailQuery orrOutcupEfficiencyDetailQuery ) throws Exception {

        LambdaQueryWrapper<OrrOutcupEfficiencyDetailEntity> lqs = new LambdaQueryWrapper();
        List<OrrOutcupEfficiencyDetailEntity> list = orrOutcupEfficiencyDetailMapper.selectList(lqs);
        return list;
    }


    /**
     * 获取 OrrOutcupEfficiencyDetail 详情
     */
    @Transactional
    public OrrOutcupEfficiencyDetailEntity getOrrOutcupEfficiencyDetailDetail( Long id) throws Exception {

        OrrOutcupEfficiencyDetailEntity orrOutcupEfficiencyDetailEntity = orrOutcupEfficiencyDetailMapper.selectById(id);
        return orrOutcupEfficiencyDetailEntity;
    }


    /**
     * 新增 OrrOutcupEfficiencyDetail
     * */
    @Transactional
    public void addOrrOutcupEfficiencyDetail(OrrOutcupEfficiencyDetailVo orrOutcupEfficiencyDetailVo) throws Exception {

        OrrOutcupEfficiencyDetailEntity orrOutcupEfficiencyDetailEntity = new OrrOutcupEfficiencyDetailEntity();
        ReflectionCopy.copyProperties( orrOutcupEfficiencyDetailEntity, orrOutcupEfficiencyDetailVo );
        orrOutcupEfficiencyDetailMapper.insert(orrOutcupEfficiencyDetailEntity);
        return;
    }


    /**
     * 更新 OrrOutcupEfficiencyDetail
     * */
    @Transactional
    public void updateOrrOutcupEfficiencyDetail( OrrOutcupEfficiencyDetailVo orrOutcupEfficiencyDetailVo) throws Exception {

        if( orrOutcupEfficiencyDetailVo.getId() == null ){
            throw GlobalException.gen(10021, "id不存在");
        }
        OrrOutcupEfficiencyDetailEntity orrOutcupEfficiencyDetailEntity = new OrrOutcupEfficiencyDetailEntity();
        ReflectionCopy.copyProperties( orrOutcupEfficiencyDetailEntity, orrOutcupEfficiencyDetailVo );
        orrOutcupEfficiencyDetailMapper.updateById(orrOutcupEfficiencyDetailEntity);
        return;
    }

    /**
     * 删除 OrrOutcupEfficiencyDetail
     * */
    @Transactional
    public void batchRemoveOrrOutcupEfficiencyDetail( List<Long> ids ) throws Exception {

        if( !ObjectUtil.isNotEmptyList(ids) ){
            throw GlobalException.gen(10011, "要删除的id不存在");
        }
        orrOutcupEfficiencyDetailMapper.deleteBatchIds(ids);
    }

}